package com.docking.heylo.web.controller;

import com.docking.heylo.dao.entity.SysUser;
import com.docking.heylo.service.ISysUserService;
import com.docking.heylo.web.dto.SysUserDto;
import com.docking.heylo.web.utils.ResultUtil;
import com.docking.heylo.web.vo.BaseVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/***
 * 系统用户管理控制器
 *
 */
@RestController
@RequestMapping("/sysUserManager")
public class SysUserManagerController {

    @Autowired
    private ISysUserService sysUserService;

    /***
     * 新增系统用户
     * @return
     */
    @RequestMapping("/saveSysUser")
    public BaseVo saveSysUser(@RequestBody @Validated(SysUserDto.NewUser.class) SysUserDto userDto){
        sysUserService.saveSysUser(userDto);
        return ResultUtil.success("新增系统用户成功");
    }

    /***
     * 系统用户列表
     *
     * @return
     */
    @PostMapping("/sysUserList")
    public BaseVo sysUserList(@RequestBody @Validated(SysUserDto.Page.class) SysUserDto userDto){
        PageInfo<Map<String, Object>> sysUserInfo = sysUserService.sysUserList(userDto);
        return ResultUtil.success("成功",sysUserInfo);
    }

    /***
     * 查看用户信息
     *
     * @return
     */
    @RequestMapping("/viewUserInfo")
    public BaseVo sysUserInfo(@RequestBody @Validated(SysUserDto.IdNotNull.class) SysUserDto sysUser){
        SysUser user = sysUserService.selectById(sysUser.getUserId());
        return ResultUtil.success("成功",user);
    }

    /***
     * 修改用户信息成功
     *
     * @return
     */
    @RequestMapping("/editUserInfo")
    public BaseVo editUserInfo(@RequestBody @Validated(SysUserDto.Edit.class) SysUserDto sysUser){
        sysUserService.editUserInfo(sysUser);
        return ResultUtil.success("修改用户信息成功");
    }

    /***
     * 重置用户密码
     *
     * @return
     */
    @RequestMapping("/resetPassword")
    public BaseVo resetPassword(@RequestBody @Validated(SysUserDto.ResetPassword.class) SysUserDto sysUser){
        sysUserService.resetPassword(sysUser);
        return ResultUtil.success("重置密码成功");
    }

    /***
     * 停用启用
     *
     * @return
     */
    @RequestMapping("/disableActivation")
    public BaseVo disableActivation(@RequestBody @Validated(SysUserDto.DisableActivation.class) SysUserDto sysUser){
        sysUserService.disableActivation(sysUser);
        return ResultUtil.success("成功");
    }

    /***
     * 用户注册统计
     *
     * @return
     */
    @RequestMapping("/registerStatistics")
    public BaseVo registerStatistics(){
        Map<String,Object> statistics = sysUserService.registerStatistics();
        return ResultUtil.success("成功", statistics);
    }




}
